<?php

namespace App\Http\Resources;

use Illuminate\Http\Resources\Json\JsonResource;

class ScoreResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function toArray($request)
    {
        $info = $this->info;
        $data = [
            'id' => $this->id,
            'type' => $this->type,
            'type_text' => $this->typeText,
            'remarks' => $this->remarks,
            'score' => ($this->score > 0 ? "+" : "-") . abs($this->score),
            'created_at' => $this->created_at->format('Y-m-d H:i'),
            'target_title' => $info['target_title'] ?? '',
            'target_username' => $info['target_username'] ?? '',
            'target_id' => $info['target_id'] ?? '',
            'action_title' => $info['action_title'] ?? '',
            'icon' => $this->icon,
        ];

        return $data;

    }

}
